package org.apache.solr.client.exception;

public class SolrServerException extends Exception {

	private String serverSideMessage;
	private int serverSideStatus;
	private String clientRequestText;

	public SolrServerException(String message, int serverSideStatus, String serverSideMessage, String requestText ) {
		super(message);
		this.serverSideStatus = serverSideStatus;
		this.serverSideMessage = serverSideMessage;
		this.clientRequestText = requestText;
	}

	public String getServerSideMessage() {
		return serverSideMessage;
	}

	public int getServerSideStatus() {
		return serverSideStatus;
	}

	@Override
	public String getMessage() {
		StringBuilder sb = new StringBuilder();
		
		String superMessage = super.getMessage();
		
		if( null != superMessage) {
			sb.append(superMessage).append("\nCaused by:\n");
		}
		
		sb.append("Server side exception, status = ").append(serverSideStatus).append(": ").append(serverSideMessage); 

		// request text
		sb.append("\nAfter sending request:\n").append( clientRequestText );
		
		return sb.toString();
	}
}
